<template>
    <div>
        <!-- 顶部滑动模块 -->
        <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<span :class="['mui-control-item',item.id === 0 ? 'mui-active' : '']" 
						v-for="item in category" 
						:key="item.id"
						@tap="getPhotoByCategary(item.id)">
							{{item.title}}
						</span>
					</div>
				</div>
			</div>
        <!-- 图片懒加载 -->
		<ul class="lazyul">
			<router-link tag="li" v-for="item in photolist" :key="item.id" :to="'/home/photoinfo/' + item.id">
				<img v-lazy="item.img_url">
				<div class="info">
					<div class="title"> {{item.title}} </div>
					<div class="content" v-html="item.content"></div>
				</div>
			</router-link>
		</ul>
    </div>
</template>

<script>
// 引入滑动模块的js
import mui from '../../../lib/mui/js/mui.js'

export default {
    data(){
        return{
			category: [],
			photolist: []
        }
    },
	created() {
		this.getPhotoCategary(),
		this.getPhotoByCategary()
	},
    methods: {
        async getPhotoCategary(){
			const {data} = await this.$http.get('/api/getimgcategory')
			// console.log(data);
		    if(data.status === 0)
			data.message.unshift({title: '全部',id: 0})
			this.category = data.message
		},
		async getPhotoByCategary(id){
			const {data} = await this.$http.get("/api/getimages/" + id)
			console.log(data);
			if(data.status === 0) 
			return (this.photolist = data.message)
		}
    },
    mounted() {
        // 当次钩子函数执行的时候，我们才可以进行插件和控件的初始化工作
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
    }
}
</script>

<style lang="scss" scoped>
    .mui-slider{
        touch-action: pan-y;
    }
	.info{
		position: absolute;
		bottom: 0;
		font-size: 17px;
		color: #fff;
		background-color: rgb(119, 116, 116);
		opacity: 0.5;
		max-height: 86px;
		overflow: hidden;
		.title{
			font-size: 14px;
		}
		.content{
			font-size: 13px;
			text-align: left;
			text-indent: 2em;
		}
	}
	.lazyul{
		list-style: none;
		padding: 10px;
		margin: 0;
		li{
			position: relative;
			background-color: #fff;
			text-align: center;
			box-shadow: 0 0 7px rgb(161, 161, 161);
			& + li{
				margin-top: 10px;
			}
			img{
				vertical-align: middle;
				width: 100%;
				height: 100%;
			}
			img[lazy="loading"] {
				width: 40px;
				height: 300px;
				margin: auto;
			}
		}
	}
</style>